package rth.entities;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.proxy.HibernateProxy;

import rth.entities.iface.IBuild;

import com.felees.hbnpojogen.persistence.IPojoGenEntity;

/**
 * Object mapping for hibernate-handled table: build.
 * 
 * @author autogenerated
 */

@Entity
@Table(name = "build", catalog = "rth")
public class Build implements Cloneable, Serializable, IPojoGenEntity, IBuild {

	/** Serial Version UID. */
	private static final long serialVersionUID = -559033222L;

	/**
	 * Use a WeakHashMap so entries will be garbage collected once all entities
	 * referring to a saved hash are garbage collected themselves.
	 */
	private static final Map<Serializable, Long> SAVED_HASHES = Collections
			.synchronizedMap(new WeakHashMap<Serializable, Long>());

	/** hashCode temporary storage. */
	private volatile Long hashCode;

	/** Field mapping. */
	private String archive;
	/** Field mapping. */
	private String buildname;
	/** Field mapping. */
	private String datecreated;
	/** Field mapping. */
	private String datefinished;
	/** Field mapping. */
	private String datereceived;
	/** Field mapping. */
	private String description;
	/** Field mapping. */
	private Long id = 0L; // init for hibernate bug workaround
	/** Field mapping. */
	private String logtimestamp;
	/** Field mapping. */
	private Long releaseid;

	/**
	 * Default constructor, mainly for hibernate use.
	 */
	public Build() {
		// Default constructor
	}

	/**
	 * Constructor taking a given ID.
	 * 
	 * @param id
	 *            to set
	 */
	public Build(Long id) {
		this.id = id;
	}

	/**
	 * Constructor taking a given ID.
	 * 
	 * @param archive
	 *            String object;
	 * @param datecreated
	 *            String object;
	 * @param datefinished
	 *            String object;
	 * @param datereceived
	 *            String object;
	 * @param id
	 *            Long object;
	 * @param logtimestamp
	 *            String object;
	 * @param releaseid
	 *            Long object;
	 */
	public Build(String archive, String datecreated, String datefinished,
			String datereceived, Long id, String logtimestamp, Long releaseid) {

		this.archive = archive;
		this.datecreated = datecreated;
		this.datefinished = datefinished;
		this.datereceived = datereceived;
		this.id = id;
		this.logtimestamp = logtimestamp;
		this.releaseid = releaseid;
	}

	/**
	 * Return the type of this class. Useful for when dealing with proxies.
	 * 
	 * @return Defining class.
	 */
	@Transient
	public Class<?> getClassType() {
		return Build.class;
	}

	/**
	 * Return the value associated with the column: archive.
	 * 
	 * @return A String object (this.archive)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 1)
	public String getArchive() {
		return this.archive;

	}

	/**
	 * Set the value related to the column: archive.
	 * 
	 * @param archive
	 *            the archive value you wish to set
	 */
	public void setArchive(final String archive) {
		this.archive = archive;
	}

	/**
	 * Return the value associated with the column: buildname.
	 * 
	 * @return A String object (this.buildname)
	 */
	@Basic(optional = true)
	@Column(length = 20)
	public String getBuildname() {
		return this.buildname;

	}

	/**
	 * Set the value related to the column: buildname.
	 * 
	 * @param buildname
	 *            the buildname value you wish to set
	 */
	public void setBuildname(final String buildname) {
		this.buildname = buildname;
	}

	/**
	 * Return the value associated with the column: datecreated.
	 * 
	 * @return A String object (this.datecreated)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 19)
	public String getDatecreated() {
		return this.datecreated;

	}

	/**
	 * Set the value related to the column: datecreated.
	 * 
	 * @param datecreated
	 *            the datecreated value you wish to set
	 */
	public void setDatecreated(final String datecreated) {
		this.datecreated = datecreated;
	}

	/**
	 * Return the value associated with the column: datefinished.
	 * 
	 * @return A String object (this.datefinished)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 19)
	public String getDatefinished() {
		return this.datefinished;

	}

	/**
	 * Set the value related to the column: datefinished.
	 * 
	 * @param datefinished
	 *            the datefinished value you wish to set
	 */
	public void setDatefinished(final String datefinished) {
		this.datefinished = datefinished;
	}

	/**
	 * Return the value associated with the column: datereceived.
	 * 
	 * @return A String object (this.datereceived)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 19)
	public String getDatereceived() {
		return this.datereceived;

	}

	/**
	 * Set the value related to the column: datereceived.
	 * 
	 * @param datereceived
	 *            the datereceived value you wish to set
	 */
	public void setDatereceived(final String datereceived) {
		this.datereceived = datereceived;
	}

	/**
	 * Return the value associated with the column: description.
	 * 
	 * @return A String object (this.description)
	 */
	@Basic(optional = true)
	@Column(length = 21845)
	public String getDescription() {
		return this.description;

	}

	/**
	 * Set the value related to the column: description.
	 * 
	 * @param description
	 *            the description value you wish to set
	 */
	public void setDescription(final String description) {
		this.description = description;
	}

	/**
	 * Return the value associated with the column: id.
	 * 
	 * @return A Long object (this.id)
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Basic(optional = false)
	@Column(name = "buildid", nullable = false)
	public Long getId() {
		return this.id;

	}

	/**
	 * Set the value related to the column: id.
	 * 
	 * @param id
	 *            the id value you wish to set
	 */
	public void setId(final Long id) {
		// If we've just been persisted and hashCode has been
		// returned then make sure other entities with this
		// ID return the already returned hash code
		if ((this.id == null || this.id == 0L) && (id != null)
				&& (this.hashCode != null)) {
			SAVED_HASHES.put(id, this.hashCode);
		}
		this.id = id;
	}

	/**
	 * Return the value associated with the column: logtimestamp.
	 * 
	 * @return A String object (this.logtimestamp)
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 19)
	public String getLogtimestamp() {
		return this.logtimestamp;

	}

	/**
	 * Set the value related to the column: logtimestamp.
	 * 
	 * @param logtimestamp
	 *            the logtimestamp value you wish to set
	 */
	public void setLogtimestamp(final String logtimestamp) {
		this.logtimestamp = logtimestamp;
	}

	/**
	 * Return the value associated with the column: releaseid.
	 * 
	 * @return A Long object (this.releaseid)
	 */
	@Basic(optional = false)
	@Column(nullable = false)
	public Long getReleaseid() {
		return this.releaseid;

	}

	/**
	 * Set the value related to the column: releaseid.
	 * 
	 * @param releaseid
	 *            the releaseid value you wish to set
	 */
	public void setReleaseid(final Long releaseid) {
		this.releaseid = releaseid;
	}

	/**
	 * Deep copy.
	 * 
	 * @return cloned object
	 * @throws CloneNotSupportedException
	 *             on error
	 */
	@Override
	public Build clone() throws CloneNotSupportedException {

		final Build copy = (Build) super.clone();

		copy.setArchive(this.getArchive());
		copy.setBuildname(this.getBuildname());
		copy.setDatecreated(this.getDatecreated());
		copy.setDatefinished(this.getDatefinished());
		copy.setDatereceived(this.getDatereceived());
		copy.setDescription(this.getDescription());
		copy.setId(this.getId());
		copy.setLogtimestamp(this.getLogtimestamp());
		copy.setReleaseid(this.getReleaseid());
		return copy;
	}

	/**
	 * Provides toString implementation.
	 * 
	 * @see java.lang.Object#toString()
	 * @return String representation of this class.
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();

		sb.append("archive: " + this.getArchive() + ", ");
		sb.append("buildname: " + this.getBuildname() + ", ");
		sb.append("datecreated: " + this.getDatecreated() + ", ");
		sb.append("datefinished: " + this.getDatefinished() + ", ");
		sb.append("datereceived: " + this.getDatereceived() + ", ");
		sb.append("description: " + this.getDescription() + ", ");
		sb.append("id: " + this.getId() + ", ");
		sb.append("logtimestamp: " + this.getLogtimestamp() + ", ");
		sb.append("releaseid: " + this.getReleaseid());
		return sb.toString();
	}

	/**
	 * Equals implementation.
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 * @param aThat
	 *            Object to compare with
	 * @return true/false
	 */
	@Override
	public boolean equals(final Object aThat) {
		Object proxyThat = aThat;

		if (this == aThat) {
			return true;
		}

		if (aThat instanceof HibernateProxy) {
			// narrow down the proxy to the class we are dealing with.
			try {
				proxyThat = ((HibernateProxy) aThat)
						.getHibernateLazyInitializer().getImplementation();
			} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
			}
		}
		if (aThat == null) {
			return false;
		}

		final Build that;
		try {
			that = (Build) proxyThat;
			if (!(that.getClassType().equals(this.getClassType()))) {
				return false;
			}
		} catch (org.hibernate.ObjectNotFoundException e) {
			return false;
		} catch (ClassCastException e) {
			return false;
		}

		boolean result = true;
		result = result
				&& (((this.getId() == null) && (that.getId() == null)) || (this
						.getId() != null && this.getId().equals(that.getId())));
		result = result
				&& (((getArchive() == null) && (that.getArchive() == null)) || (getArchive() != null && getArchive()
						.equals(that.getArchive())));
		result = result
				&& (((getBuildname() == null) && (that.getBuildname() == null)) || (getBuildname() != null && getBuildname()
						.equals(that.getBuildname())));
		result = result
				&& (((getDatecreated() == null) && (that.getDatecreated() == null)) || (getDatecreated() != null && getDatecreated()
						.equals(that.getDatecreated())));
		result = result
				&& (((getDatefinished() == null) && (that.getDatefinished() == null)) || (getDatefinished() != null && getDatefinished()
						.equals(that.getDatefinished())));
		result = result
				&& (((getDatereceived() == null) && (that.getDatereceived() == null)) || (getDatereceived() != null && getDatereceived()
						.equals(that.getDatereceived())));
		result = result
				&& (((getDescription() == null) && (that.getDescription() == null)) || (getDescription() != null && getDescription()
						.equals(that.getDescription())));
		result = result
				&& (((getLogtimestamp() == null) && (that.getLogtimestamp() == null)) || (getLogtimestamp() != null && getLogtimestamp()
						.equals(that.getLogtimestamp())));
		result = result
				&& (((getReleaseid() == null) && (that.getReleaseid() == null)) || (getReleaseid() != null && getReleaseid()
						.equals(that.getReleaseid())));
		return result;
	}

	/**
	 * Calculate the hashcode.
	 * 
	 * @see java.lang.Object#hashCode()
	 * @return a calculated number
	 */
	@Override
	public int hashCode() {
		if (this.hashCode == null) {
			synchronized (this) {
				if (this.hashCode == null) {
					Long newHashCode = null;

					if (getId() != null) {
						newHashCode = SAVED_HASHES.get(getId());
					}

					if (newHashCode == null) {
						if (getId() != null && getId() != 0L) {
							newHashCode = getId();
						} else {
							newHashCode = (long) super.hashCode();

						}
					}

					this.hashCode = newHashCode;
				}
			}
		}
		return (int) (this.hashCode & 0xffffff);
	}

}
